#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'AWS/EC2'
require 'basic_configuration'
require 'aws_context'
require 'pp'

# Associate an ElasticIP address with an instance

if ARGV[0] == '-?' || ARGV.size != 2 then
  puts "usage: associate-address instance-id public-ip"
  exit 1
end
instance_id = ARGV[0]
public_ip = ARGV[1]

Signal.trap("INT") do
  exit 2
end

config = BasicConfiguration.new
ec2 = AwsContext.instance.ec2(*config.keys)
begin
  res = ec2.associate_address(instance_id, public_ip)
  #pp res
  puts res
rescue
  puts "error #{$!} #{instance_id} #{public_ip}"
  exit 1
end

